package com.zaizai.controller;


import com.zaizai.aop.AutoLog;
import com.zaizai.domain.AjaxResult;
import com.zaizai.domain.Commodity;
import com.zaizai.service.ICommodityService;
import com.zaizai.utils.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.zaizai.domain.AjaxResult.success;

/**
 * 商品详情Controller
 *
 * @author zaiZai
 * @date 2024-10-21
 */
@RestController
@RequestMapping("/commodity")
public class CommodityController extends BaseController {
    @Autowired
    private ICommodityService commodityService;

    /**
     * 查询商品详情列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Commodity commodity) {
        startPage();
        List<Commodity> list = commodityService.selectCommodityList(commodity);
        return getDataTable(list);
    }

    /**
     * 获取商品详情详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(commodityService.selectCommodityById(id));
    }

    /**
     * 新增商品详情
     */
    @PostMapping
    @AutoLog("新增商品信息")
    public AjaxResult add(@RequestBody Commodity commodity) {
        return success(commodityService.insertCommodity(commodity));
    }

    /**
     * 修改商品详情
     */
    @PutMapping
    @AutoLog("修改商品信息")
    public AjaxResult edit(@RequestBody Commodity commodity) {
        return success(commodityService.updateCommodity(commodity));
    }

    /**
     * 删除商品详情
     */
    @DeleteMapping("/{ids}")
    @AutoLog("删除商品信息")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return success(commodityService.deleteCommodityByIds(ids));
    }
}
